package com.myapp.ruyixing.http;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.myapp.ruyixing.Config;
import com.myapp.ruyixing.model.Message;
import com.myapp.ruyixing.utils.CompatibilityUtils;
import com.myapp.ruyixing.utils.ImageUtils;
import com.myapp.ruyixing.utils.LogUtils;
import com.myapp.ruyixing.utils.LoginHelper;

public class RYHttpClient {
	private static final String TAG = "RYHttpClient";

	private static final String BASE_URL = "http://www.17ruyi.com/api.php";

	private static AsyncHttpClient client = new AsyncHttpClient();

	public static void cancleRequest(Context context) {
		client.cancelRequests(context, true);
	}

	public static void recordCall(Context context,
			RYHttpResponseHandler handler, String bduss, String shopid,
			String phone) {
		RequestParams params = getParams("app_member", "call");
		params.put("bduss", bduss);
		params.put("shopid", shopid);
		params.put("phone", phone);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void getWholeCity(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "wholecity");
		params.put("cityid", Config.sCityId);
		handler.setParser(new WholeCityParser());

		get(context, params, handler);
	}

	public static void getCityHotCategory(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "hotcategory");
		params.put("cityid", Config.sCityId);
		handler.setParser(new CityHotCategoryParser());

		get(context, params, handler);
	}

	public static void getCityHotDistrict(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "hotbusinessdistrict");
		params.put("cityid", Config.sCityId);
		handler.setParser(new CityHotDistrictParser());

		get(context, params, handler);
	}

	public static void getMemberDetail(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "cardlist");
		params.put("cityid", Config.sCityId);
		handler.setParser(new MemberDetailParser());

		get(context, params, handler);
	}

	public static void getMyUserInfo(Context context,
			RYHttpResponseHandler handler, String bduss) {
		RequestParams params = getParams("app_member", "mycenter");
		params.put("bduss", bduss);
		handler.setParser(new UserInfoParser());

		get(context, params, handler);
	}

	public static void getOthersUserInfo(Context context,
			RYHttpResponseHandler handler, String userid, String bduss) {
		RequestParams params = getParams("app_member", "otherscenter");
		params.put("otheruserid", userid);
		params.put("bduss", bduss);
		handler.setParser(new UserInfoParser());

		get(context, params, handler);
	}

	public static void applyMemberCard(Context context,
			RYHttpResponseHandler handler, String cardId) {
		RequestParams params = getParams("app_info", "applyforcard");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("cardid", cardId);
		handler.setParser(new ApplyResultParser());

		get(context, params, handler);
	}

	public static void getNearbyStore(Context context,
			RYHttpResponseHandler handler, String distance, String type,
			String order, String districtid, double lat, double lng) {
		RequestParams params = getParams("app_nearby", "nearby");
		params.put("cityid", Config.sCityId);
		params.put("pn", "0");
		params.put("rn", "65535");
		params.put("lat", "" + lat);
		params.put("lon", "" + lng);
		params.put("distance", distance);
		params.put("type", type);
		params.put("order", order);
		if (districtid != null) {
			params.put("districtid", districtid);
		}
		handler.setParser(new NearbyStoreParser());

		get(context, params, handler);
	}

	public static void getPrivilege(Context context,
			RYHttpResponseHandler handler, int type, String distance,
			String order) {
		RequestParams params = getParams("app_nearby", "discount");
		params.put("cityid", Config.sCityId);
		params.put("pn", "0");
		params.put("rn", "65535");
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());

		}
		params.put("distance", distance);
		params.put("order", order);
		params.put("type", "" + type);
		handler.setParser(new PrivilegeParser());

		get(context, params, handler);
	}

	public static void submitFeedback(Context context,
			RYHttpResponseHandler handler, String feeback, String phone) {
		RequestParams params = new RequestParams();
		params.put("content", feeback);
		params.put("phone", phone);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		handler.setParser(new FeedbackParser());

		post(context, BASE_URL + "?op=app_member&action=myfeedback", params,
				handler);
	}

	public static void getCardBalance(Context context,
			RYHttpResponseHandler handler, String bduss) {
		RequestParams params = getParams("member", "balance");
		params.put("bduss", bduss);
		handler.setParser(new CardBalanceParser());
		get(context, params, handler);
	}

	public static void doFollow(Context context, RYHttpResponseHandler handler,
			String bduss, String aid, int status) {
		RequestParams params = getParams("app_member", "op_attention");
		params.put("bduss", bduss);
		params.put("aid", aid);
		params.put("status", status + "");
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void doModifyUser(Context context,
			RYHttpResponseHandler handler, String bduss, String nickname,
			int sex, String cityid) {
		RequestParams params = getParams("app_member", "submitupdate");
		params.put("bduss", bduss);
		params.put("nickname", nickname);
		params.put("sex", sex + "");
		params.put("cityid", cityid);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void getLiveCityList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_member", "citylist");
		handler.setParser(new CityListParser());
		get(context, params, handler);
	}

	public static void getTrainCityList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_huoche", "getcity");
		handler.setParser(new CityListParser());
		get(context, params, handler);
	}

	public static void getPlaneCityList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_plane", "getcity");
		handler.setParser(new CityListParser());
		get(context, params, handler);
	}

	public static void getConsumptionRecordList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("member", "consumption");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ConsumptionRecordListParser());
		get(context, params, handler);
	}

	public static void getFoodList(Context context,
			RYHttpResponseHandler handler, String cityid, int pn, int rn,
			double lat, double lon) {
		RequestParams params = getParams("app_nearby", "foodlist");
		params.put("cityid", cityid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new FoodListParser());
		get(context, params, handler);
	}

	public static void getFoodListV2(Context context,
			RYHttpResponseHandler handler, String type, String order,
			String distance) {
		RequestParams params = getParams("app_nearby", "foodlist");
		params.put("cityid", Config.sCityId);
		params.put("pn", "0");
		params.put("rn", "65535");
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());

		}
		params.put("distance", distance);
		params.put("type", type);
		params.put("order", order);

		handler.setParser(new FoodListParser());

		get(context, params, handler);
	}

	public static void getFoodCategory(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "foodcategory");

		handler.setParser(new FoodCategoryParser());

		get(context, params, handler);
	}

	public static void getShopList(Context context,
			RYHttpResponseHandler handler, String cityid, String foodname,
			int pn, int rn, double lat, double lon) {
		RequestParams params = getParams("app_nearby", "restaurantlist");
		params.put("cityid", cityid);
		params.put("foodname", foodname);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new ShopListParser());
		get(context, params, handler);
	}

	public static void getFansList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "myfans");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new FansListParser());
		get(context, params, handler);
	}

	public static void getShopPicList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			int pn, int rn) {
		RequestParams params = getParams("app_shop", "shoppiclist");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ShopPicListParser());
		get(context, params, handler);
	}

	public static void getActivityList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String status, String title, int pn, int rn) {
		RequestParams params = getParams("app_shop", "activitylist");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("status", status);
		params.put("title", title);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ActivityListParser());
		get(context, params, handler);
	}

	public static void getImpressionList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String status, int pn, int rn) {
		RequestParams params = getParams("app_shop", "impressionlist");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("status", status);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ImpressionListParser());
		get(context, params, handler);
	}

	public static void getReviewList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String status, int pn, int rn) {
		RequestParams params = getParams("app_shop", "reviewlist");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("status", status);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ReviewListParser());
		get(context, params, handler);
	}

	public static void getOrderList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String status, int pn, int rn) {
		RequestParams params = getParams("app_shop", "orderlist");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("status", status);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new OrderListParser());
		get(context, params, handler);
	}

	public static void getActivityOrderList(Context context,
			RYHttpResponseHandler handler, String shopbduss, String aid,
			String status, int pn, int rn) {
		RequestParams params = getParams("app_shop", "activityorderlist");
		params.put("shopbduss", shopbduss);
		params.put("aid", aid);
		params.put("status", status);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new ActivityOrderListParser());
		get(context, params, handler);
	}

	public static void getOthersFansList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "othersfans");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new FansListParser());
		get(context, params, handler);
	}

	public static void getFollowList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "myattentions");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new FollowListParser());
		get(context, params, handler);
	}

	public static void getOthersFollowList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "othersattentions");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new FollowListParser());
		get(context, params, handler);
	}

	public static void getMyPictureList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "mypictures");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyPictureListParser());
		get(context, params, handler);
	}

	public static void getOthersPictureList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "otherspictures");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyPictureListParser());
		get(context, params, handler);
	}

	public static void getMySigninList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "mysignins");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MySigninListParser());
		get(context, params, handler);
	}

	public static void getOthersSigninList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "otherssignins");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MySigninListParser());
		get(context, params, handler);
	}

	public static void getMyFavoriteList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "myfavorite");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyFavoriteListParser());
		get(context, params, handler);
	}

	public static void getOthersFavoriteList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "othersfavorite");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyFavoriteListParser());
		get(context, params, handler);
	}

	public static void getMyReviewList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "myreviews");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyReviewListParser());
		get(context, params, handler);
	}

	public static void getOthersReviewList(Context context,
			RYHttpResponseHandler handler, String userid, int pn, int rn) {
		RequestParams params = getParams("app_member", "othersreviews");
		params.put("userid", userid);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyReviewListParser());
		get(context, params, handler);
	}

	public static void getMyOrderList(Context context,
			RYHttpResponseHandler handler, String ordertype, String bduss,
			int pn, int rn) {
		RequestParams params = getParams("app_member", "myorders");
		params.put("bduss", bduss);
		params.put("type", ordertype);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyOrderListParser());
		get(context, params, handler);
	}

	public static void getMyScoreList(Context context,
			RYHttpResponseHandler handler, String bduss, int pn, int rn) {
		RequestParams params = getParams("app_member", "myscorelist");
		params.put("bduss", bduss);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		handler.setParser(new MyScoreListParser());
		get(context, params, handler);
	}

	public static void getCityList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "citylist");
		handler.setParser(new CityListParser());
		get(context, params, handler);
	}

	public static void getPushMessage(Context context,
			RYHttpResponseHandler handler, String cityid) {
		RequestParams params = getParams("app_nearby", "pushmsg");
		params.put("cityid", cityid);
		handler.setParser(new PushMessageParser());
		get(context, params, handler);
	}

	public static void getSearchShopList(Context context,
			RYHttpResponseHandler handler, String cityid, String shopname,
			double lat, double lon) {
		RequestParams params = getParams("app_nearby", "searchshopname");
		params.put("cityid", cityid);
		params.put("shopname", shopname);
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new NearbyStoreParser());
		get(context, params, handler);
	}

	public static void getShopDetail(Context context,
			RYHttpResponseHandler handler, String shopid, String bduss,
			double lat, double lon) {
		RequestParams params = getParams("app_nearby", "shopdetail");
		params.put("shopid", shopid);
		if (!TextUtils.isEmpty(bduss)) {
			params.put("bduss", bduss);
		}
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new ShopDetailParser());
		get(context, params, handler);
	}

	public static void getShopInfo(Context context,
			RYHttpResponseHandler handler, String shopid, String shopbduss) {
		RequestParams params = getParams("app_shop", "shopinfo");
		params.put("shopid", shopid);
		params.put("shopbduss", shopbduss);
		handler.setParser(new ShopInfoParser());
		get(context, params, handler);
	}

	public static void getActivityInfo(Context context,
			RYHttpResponseHandler handler, String aid, String shopbduss) {
		RequestParams params = getParams("app_shop", "activityinfo");
		params.put("aid", aid);
		params.put("shopbduss", shopbduss);
		handler.setParser(new ActivityInfoParser());
		get(context, params, handler);
	}

	public static void getOrderInfo(Context context,
			RYHttpResponseHandler handler, String orderid, String shopbduss) {
		RequestParams params = getParams("app_shop", "orderinfo");
		params.put("orderid", orderid);
		params.put("shopbduss", shopbduss);
		handler.setParser(new OrderInfoParser());
		get(context, params, handler);
	}

	public static void getActivityOrderInfo(Context context,
			RYHttpResponseHandler handler, String dataid, String shopbduss) {
		RequestParams params = getParams("app_shop", "activityorderinfo");
		params.put("dataid", dataid);
		params.put("shopbduss", shopbduss);
		handler.setParser(new ActivityOrderInfoParser());
		get(context, params, handler);
	}

	public static void getDiscountDetail(Context context,
			RYHttpResponseHandler handler, String id, String bduss, double lat,
			double lon) {
		RequestParams params = getParams("app_nearby", "discountinfos");
		params.put("id", id);
		params.put("bduss", bduss);
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new DiscountDetailParser());
		get(context, params, handler);
	}

	public static void getFoodDetail(Context context,
			RYHttpResponseHandler handler, String id, String bduss, double lat,
			double lon) {
		RequestParams params = getParams("app_nearby", "foodinfos");
		params.put("id", id);
		params.put("bduss", bduss);
		params.put("lat", lat + "");
		params.put("lon", lon + "");
		handler.setParser(new FoodDetailParser());
		get(context, params, handler);
	}

	public static void sendPhone(Context context,
			RYHttpResponseHandler handler, String phone) {
		RequestParams params = getParams("app_member", "sendphone");
		params.put("phone", phone);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void submitFavorite(Context context,
			RYHttpResponseHandler handler, String bduss, String id) {
		RequestParams params = getParams("app_member", "submitfavorite");
		params.put("bduss", bduss);
		params.put("shopid", id);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void delFavorite(Context context,
			RYHttpResponseHandler handler, String bduss, String id) {
		RequestParams params = getParams("app_member", "delfavorite");
		params.put("bduss", bduss);
		params.put("shopid", id);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void updateShop(Context context,
			RYHttpResponseHandler handler, String shopid, String shopbduss,
			String field, String content, String latitude, String longitude) {
		RequestParams params = new RequestParams();
		params.put("shopid", shopid);
		params.put("shopbduss", shopbduss);
		params.put("field", field);
		params.put("content", content);
		params.put("latitude", latitude);
		params.put("longitude", longitude);
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_shop&action=updateshop", params,
				handler);
	}

	public static void updateShopPic(Context context,
			RYHttpResponseHandler handler, String shopid, String shopbduss,
			String id, String status) {
		RequestParams params = getParams("app_shop", "updateshoppic");
		params.put("shopid", shopid);
		params.put("shopbduss", shopbduss);
		params.put("id", id);
		params.put("status", status);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void updateActivityOrder(Context context,
			RYHttpResponseHandler handler, String shopbduss, String aid,
			String dataid, String status, String content) {
		RequestParams params = new RequestParams();
		params.put("aid", aid);
		params.put("shopbduss", shopbduss);
		params.put("dataid", dataid);
		params.put("status", status);
		params.put("content", content);
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_shop&action=updateactivityorder",
				params, handler);
	}

	public static void sendActivitySMS(Context context,
			RYHttpResponseHandler handler, String shopbduss, String dataid,
			String name, String phone, String content) {
		RequestParams params = new RequestParams();
		params.put("shopbduss", shopbduss);
		params.put("dataid", dataid);
		params.put("name", name);
		params.put("phone", phone);
		params.put("content", content);
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_shop&action=sendactivitysms", params,
				handler);
	}

	public static void updateImpression(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String id, String status) {
		RequestParams params = getParams("app_shop", "updateimpression");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("id", id);
		params.put("status", status);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void delImpression(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String id) {
		RequestParams params = getParams("app_shop", "delimpression");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("id", id);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void updateReview(Context context,
			RYHttpResponseHandler handler, String shopbduss, String shopid,
			String id, String status) {
		RequestParams params = getParams("app_shop", "updatereview");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("id", id);
		params.put("status", status);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void updateOrder(Context context,
			RYHttpResponseHandler handler, String shopbduss, String orderid,
			String status, String paymethod, String price, String remark) {
		RequestParams params = new RequestParams();
		params.put("shopbduss", shopbduss);
		params.put("orderid", orderid);
		params.put("price", price);
		params.put("status", status);
		params.put("chargetype", paymethod);
		params.put("remark", remark);
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_shop&action=updateorder", params,
				handler);
	}

	public static void sendSMS(Context context, RYHttpResponseHandler handler,
			String shopbduss, String orderid, String name, String phone,
			String content) {
		RequestParams params = new RequestParams();
		params.put("shopbduss", shopbduss);
		params.put("orderid", orderid);
		params.put("name", name);
		params.put("phone", phone);
		params.put("content", content);
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_shop&action=sendsms", params, handler);
	}

	public static void delOrder(Context context, RYHttpResponseHandler handler,
			String shopbduss, String shopid, String orderid) {
		RequestParams params = getParams("app_shop", "delorder");
		params.put("shopbduss", shopbduss);
		params.put("shopid", shopid);
		params.put("orderid", orderid);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void delActivityOrder(Context context,
			RYHttpResponseHandler handler, String shopbduss, String dataid) {
		RequestParams params = getParams("app_shop", "delactivityorder");
		params.put("shopbduss", shopbduss);
		params.put("dataid", dataid);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void checkICode(Context context,
			RYHttpResponseHandler handler, String phone, String icode) {
		RequestParams params = getParams("app_member", "checkicode");
		params.put("phone", phone);
		params.put("icode", icode);
		handler.setParser(new ModelParser());
		get(context, params, handler);
	}

	public static void register(Context context, RYHttpResponseHandler handler,
			String phone, String username, String password) {
		RequestParams params = new RequestParams();
		params.put("phone", phone);
		params.put("username", username);
		params.put("password", password);
		params.put("type", "phone");
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_member&action=register", params,
				handler);
	}

	public static void registerByEmail(Context context,
			RYHttpResponseHandler handler, String email, String username,
			String password) {
		RequestParams params = new RequestParams();
		params.put("email", email);
		params.put("username", username);
		params.put("password", password);
		params.put("type", "email");
		handler.setParser(new ModelParser());
		post(context, BASE_URL + "?op=app_member&action=register", params,
				handler);
	}

	public static void modifyPassword(Context context,
			RYHttpResponseHandler handler, String bduss, String oldPassword,
			String newPassword) {
		RequestParams params = new RequestParams();
		params.put("bduss", bduss);
		params.put("oldpassword", oldPassword);
		params.put("newpassword", newPassword);
		handler.setParser(new ModifyPasswordParser());
		post(context, BASE_URL + "?op=app_member&action=modifypassword",
				params, handler);
	}

	public static void doLogin(Context context, RYHttpResponseHandler handler,
			String username, String password) {
		RequestParams params = new RequestParams();
		params.put("username", username);
		params.put("password", password);
		handler.setParser(new LoginParser());
		post(context, BASE_URL + "?op=app_member&action=login", params, handler);
	}

	public static void doShopLogin(Context context,
			RYHttpResponseHandler handler, String username, String password) {
		RequestParams params = new RequestParams();
		params.put("username", username);
		params.put("password", password);
		handler.setParser(new ShopLoginParser());
		post(context, BASE_URL + "?op=app_shop&action=login", params, handler);
	}

	public static void getReserve(Context context,
			RYHttpResponseHandler handler, String bduss, String shopid) {
		RequestParams params = getParams("app_member", "onlineorder");
		params.put("bduss", bduss);
		params.put("shopid", shopid);
		handler.setParser(new ReserveParser());
		get(context, params, handler);
	}

	public static void doReserve(Context context,
			RYHttpResponseHandler handler, String bduss, String shopid,
			String name, int sex, String phone, String date, String time,
			String num, String type, String content) {
		RequestParams params = new RequestParams();
		params.put("bduss", bduss);
		params.put("shopid", shopid);
		params.put("name", name);
		params.put("sex", sex + "");
		params.put("phone", phone);
		params.put("date", date);
		params.put("time", time);
		params.put("person", num);
		params.put("type", type);
		params.put("content", content);
		handler.setParser(new ReservationParser());
		post(context, BASE_URL + "?op=app_member&action=submitorder", params,
				handler);
	}

	public static void doActivityReserve(Context context,
			RYHttpResponseHandler handler, String bduss, String aid,
			String name, String mobile, String content) {
		RequestParams params = new RequestParams();
		params.put("bduss", bduss);
		params.put("aid", aid);
		params.put("name", name);
		params.put("phone", mobile);
		params.put("content", content);
		handler.setParser(new ReservationParser());
		post(context, BASE_URL + "?op=app_member&action=submitactivityorder",
				params, handler);
	}

	public static void getTrains(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String time, int traintype, int tickettype, int starttime,
			int endtime, int timesort, int pricesort) {
		RequestParams params = getParams("app_huoche", "trainsearch");
		params.put("from", fromCity);
		params.put("to", toCity);
		params.put("time", time);
		params.put("traintype", "" + traintype);
		params.put("tickettype", "" + tickettype);
		params.put("starttime", "" + starttime);
		params.put("endtime", "" + endtime);
		params.put("timesort", "" + timesort);
		params.put("pricesort", "" + pricesort);

		handler.setParser(new TrainSearchListParser());
		get(context, params, handler);
	}

	public static void getTrainSeats(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String time, String traincode) {
		RequestParams params = getParams("app_huoche", "getseatlist");
		params.put("from", fromCity);
		params.put("to", toCity);
		params.put("time", time);
		params.put("traincode", traincode);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new TrainSeatListParser());
		get(context, params, handler);
	}

	public static void commitTrainOrder(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String time, String traincode, String starttime, String ticketname,
			String ticketprice, String mobile, String name1, String code1,
			String type1, String birthday1) {
		RequestParams params = new RequestParams();
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("from", fromCity);
		params.put("to", toCity);
		params.put("time", time);
		params.put("traincode", traincode);
		params.put("starttime", starttime);
		params.put("ticketname", ticketname);
		params.put("ticketprice", ticketprice);
		params.put("mobile", mobile);
		params.put("name1", name1);
		params.put("code1", code1);
		params.put("type1", type1);
		params.put("birthday1", birthday1);

		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_huoche&action=trainsubmit", params,
				handler);
	}

	public static void getAirlines(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String fromdate, String type, int carbins, int time,
			String company, int timesort, int pricesort) {
		RequestParams params = getParams("app_plane", "flightinfo");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("fromcity", fromCity);
		params.put("tocity", toCity);
		params.put("fromdate", fromdate);
		params.put("carbins", "" + carbins);
		params.put("time", "" + time);
		params.put("type", type);
		params.put("company", company);
		params.put("timesort", "" + timesort);
		params.put("pricesort", "" + pricesort);

		handler.setParser(new AirlineSearchListParser());
		get(context, params, handler);
	}

	public static void getAirCarbins(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String time, String airline, int type) {
		RequestParams params = getParams("app_plane", "updatecarbins");
		params.put("fromcity", fromCity);
		params.put("tocity", toCity);
		params.put("fromdate", time);
		params.put("airline", airline);
		params.put("type", "" + type);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new AirCarbinParser());
		get(context, params, handler);
	}

	public static void commitAirlineOrder(Context context,
			RYHttpResponseHandler handler, String fromCity, String toCity,
			String airCompanyName, String Airline, String airplaneType,
			String startAirportName, String endAirportName, String Stime,
			String cabintypename, String Price, String airportFee,
			String fuelFee, String mobile, String name1, String code1,
			String type1, String birthday1) {
		RequestParams params = new RequestParams();
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("fromcity", fromCity);
		params.put("tocity", toCity);
		params.put("airCompanyName", airCompanyName);
		params.put("airline", Airline);
		params.put("airplaneType", airplaneType);
		params.put("startAirportName", startAirportName);
		params.put("endAirportName", endAirportName);
		params.put("fromdate", Stime);
		params.put("cabintypename", cabintypename);
		params.put("price", Price);
		params.put("airportFee", airportFee);
		params.put("fuelFee", fuelFee);
		params.put("mobile", mobile);
		params.put("name1", name1);
		params.put("code1", code1);
		params.put("type1", type1);
		params.put("birthday1", birthday1);

		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_plane&action=submitplanes", params,
				handler);
	}

	public static void getScoreMall(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_info", "integralgoods");
		params.put("pn", "0");
		params.put("rn", "65535");
		handler.setParser(new ShopMallListParser());
		get(context, params, handler);
	}

	public static void tranferScoreItem(Context context,
			RYHttpResponseHandler handler, String goodsid, String num,
			String name, String phone, String message) {
		RequestParams params = new RequestParams();
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("goodsid", goodsid);
		params.put("num", num);
		params.put("name", name);
		params.put("phone", phone);
		params.put("message", message);
		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_info&action=forgoods", params,
				handler);
	}

	public static void getRankCategory(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_nearby", "topcategory");
		params.put("cityid", Config.sCityId);
		handler.setParser(new RankCategoryParser());
		get(context, params, handler);
	}

	public static void getRankMoreCategory(Context context,
			RYHttpResponseHandler handler, String typeid) {
		RequestParams params = getParams("app_nearby", "topmore");
		params.put("cityid", Config.sCityId);
		params.put("typeid", typeid);
		handler.setParser(new RankMoreCategoryParser());
		get(context, params, handler);
	}

	public static void getTopShopList(Context context,
			RYHttpResponseHandler handler, String typeid) {
		RequestParams params = getParams("app_nearby", "topshoplist");
		params.put("cityid", Config.sCityId);
		params.put("pn", "0");
		params.put("rn", "65535");
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());

		}
		params.put("type", typeid);
		handler.setParser(new NearbyStoreParser());

		get(context, params, handler);
	}

	public static void getShopRemarkList(Context context,
			RYHttpResponseHandler handler, String shopid) {
		RequestParams params = getParams("app_nearby", "reviewlist");
		params.put("shopid", shopid);
		params.put("pn", "0");
		params.put("rn", "65535");
		handler.setParser(new ShopRemarkParser());

		get(context, params, handler);
	}

	public static void getShopSigninList(Context context,
			RYHttpResponseHandler handler, String shopid) {
		RequestParams params = getParams("app_nearby", "signinlist");
		params.put("shopid", shopid);
		params.put("pn", "0");
		params.put("rn", "65535");
		handler.setParser(new ShopSigninParser());

		get(context, params, handler);
	}

	public static void getShopTrafficAndTime(Context context,
			RYHttpResponseHandler handler, String shopid) {
		RequestParams params = getParams("app_nearby", "moreinfos");
		params.put("shopid", shopid);
		handler.setParser(new ShopMoreInfoParser());

		get(context, params, handler);
	}

	public static void getOtherShop(Context context,
			RYHttpResponseHandler handler, String shopid) {
		RequestParams params = getParams("app_nearby", "othershoplist");
		params.put("shopid", shopid);
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());

		}
		handler.setParser(new NearbyStoreParser());

		get(context, params, handler);
	}

	public static void sendShopSignin(Context context,
			RYHttpResponseHandler handler, String shopid, String content,
			int score) {
		RequestParams params = new RequestParams();
		params.put("shopid", shopid);
		params.put("content", content);
		params.put("score", "" + score);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_nearby&action=submitsignin", params,
				handler);
	}

	public static void sendShopRemark(Context context,
			RYHttpResponseHandler handler, String shopid, String content,
			int score, int price) {
		RequestParams params = new RequestParams();
		params.put("shopid", shopid);
		params.put("content", content);
		params.put("score", "" + score);
		params.put("price", "" + price);
		params.put("cityid", Config.sCityId);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_nearby&action=submitreview", params,
				handler);
	}

	public static void sendShopError(Context context,
			RYHttpResponseHandler handler, String shopid, String content,
			String email) {
		RequestParams params = new RequestParams();
		params.put("shopid", shopid);
		params.put("content", content);
		params.put("email", email);
		params.put("cityid", Config.sCityId);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new ApplyResultParser());

		post(context, BASE_URL + "?op=app_nearby&action=submiterror", params,
				handler);
	}

	public static void getPhotoClass(Context context,
			RYHttpResponseHandler handler, String shopid, String typeid) {
		RequestParams params = getParams("app_photo", "categorypic");
		params.put("shopid", shopid);
		params.put("typeid", typeid);

		handler.setParser(new ShopPhotoClassParser());

		get(context, params, handler);
	}

	public static void getMyNotifyList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_member", "notify");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("pn", "0");
		params.put("rn", "65535");

		handler.setParser(new NotifyListParser());

		get(context, params, handler);
	}

	public static void getMyDirectMessageList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_member", "mymessage");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("pn", "0");
		params.put("rn", "65535");

		handler.setParser(new DirectMessageListParser());

		get(context, params, handler);
	}

	public static void getMyReplyList(Context context,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_member", "reply");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("pn", "0");
		params.put("rn", "65535");

		handler.setParser(new ReplyListParser());

		get(context, params, handler);
	}

	public static void getMessageDetail(Context context,
			RYHttpResponseHandler handler, String readname) {
		RequestParams params = getParams("app_member", "mymessageinfo");
		params.put("bduss", LoginHelper.getInstance().getBDUSS());
		params.put("readname", readname);

		handler.setParser(new DMDetailParser());

		get(context, params, handler);
	}

	public static void sendDirectMessage(Context context,
			RYHttpResponseHandler handler, String readname, String content) {
		RequestParams params = new RequestParams();
		params.put("readname", readname);
		params.put("message", content);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new DMDetailParser());

		post(context, BASE_URL + "?op=app_member&action=submitmymessage",
				params, handler);
	}

	public static void getScoreChangeDetail(Context context,
			RYHttpResponseHandler handler, String goodsid) {
		RequestParams params = getParams("app_info", "integralgoodsinfo");
		params.put("goodsid", goodsid);

		handler.setParser(new ScoreChangeDetailParser());

		get(context, params, handler);
	}

	public static void getScoreRemarkList(Context context,
			RYHttpResponseHandler handler, String goodsid) {
		RequestParams params = getParams("app_info", "morereview");
		params.put("goodsid", goodsid);
		params.put("pn", "0");
		params.put("rn", "65535");

		handler.setParser(new ScoreRemarkListParser());

		get(context, params, handler);
	}

	public static void getScoreExchangeList(Context context,
			RYHttpResponseHandler handler, String goodsid) {
		RequestParams params = getParams("app_info", "morechange");
		params.put("goodsid", goodsid);
		params.put("pn", "0");
		params.put("rn", "65535");

		handler.setParser(new ScoreExchangeListParser());

		get(context, params, handler);
	}

	public static void getScoreOrder(Context context,
			RYHttpResponseHandler handler, String goodsid) {
		RequestParams params = getParams("app_info", "pointdata");
		params.put("goodsid", goodsid);
		params.put("bduss", LoginHelper.getInstance().getBDUSS());

		handler.setParser(new ScoreOrderParser());

		get(context, params, handler);
	}

	public static void uploadPhotos(final Activity activity,
			RYHttpResponseHandler handler, String shopid, String file1,
			String typeparent1, String filetype1, String fileTypeName1) {
		uploadPhotos(activity, handler, shopid, file1, typeparent1, filetype1,
				fileTypeName1, null, null, null, null);
	}

	public static void uploadPhotos(final Activity activity,
			final RYHttpResponseHandler handler, final String shopid,
			final String file1, final String typeparent1,
			final String filetype1, final String fileTypeName1,
			final String file2, final String typeparent2,
			final String filetype2, final String fileTypeName2) {
		final Context appContext = activity.getApplicationContext();
		new Thread(new Runnable() {

			@Override
			public void run() {
				Map<String, String> params = new HashMap<String, String>();
				Map<String, File> files = new HashMap<String, File>();
				params.put("shopid", shopid);
				params.put("bduss", LoginHelper.getInstance().getBDUSS());

				if (TextUtils.isEmpty(file1) == false) {
					File sfile1 = new File(file1);
					params.put("filename1", sfile1.getName());
					params.put("filetypeid1", filetype1);
					params.put("fileparentid1", typeparent1);
					params.put("filetypename1", fileTypeName1);
					files.put("uploadfile1", sfile1);
				}

				if (TextUtils.isEmpty(file2) == false) {
					File sfile2 = new File(file2);
					params.put("filename2", sfile2.getName());
					params.put("filetypeid2", filetype2);
					params.put("fileparentid2", typeparent2);
					params.put("filetypename2", fileTypeName2);
					files.put("uploadfile2", sfile2);
				}

				try {
					String resp = post(BASE_URL
							+ "?op=app_photo&action=photoupload", params,
							files, LoginHelper.getInstance().getBDUSS(),
							appContext);

					LogUtils.LOGD(TAG, "upload resp : " + resp);
					JSONObject jo = new JSONObject(resp);
					final Message message = new Message();
					if (jo != null) {
						message.errno = jo.optInt("errno", -1);
						message.msg = jo.optString("msg");

						if (message.errno == 0) {
							activity.runOnUiThread(new Runnable() {

								@Override
								public void run() {
									handler.onSuccess(message);
								}
							});

							return;
						}
					}
				} catch (IOException e) {
					e.printStackTrace();
				} catch (JSONException e) {
					e.printStackTrace();
				}

				activity.runOnUiThread(new Runnable() {

					@Override
					public void run() {
						handler.onFailure(null);
					}
				});

			}
		}).start();
	}

	public static void addShop(final Activity activity,
			final RYHttpResponseHandler handler, final String shopname,
			final String uploadfile, final String category,
			final String address, final String nearby, final String phone,
			final String week, final String datetime, final String name,
			final String lat, final String lon) {
		final Context appContext = activity.getApplicationContext();
		new Thread(new Runnable() {

			@Override
			public void run() {
				Map<String, String> params = new HashMap<String, String>();
				Map<String, File> files = new HashMap<String, File>();
				params.put("bduss", LoginHelper.getInstance().getBDUSS());

				File sfile1 = new File(uploadfile);
				params.put("shopname", shopname);
				params.put("category", category);
				params.put("address", address);
				params.put("nearby", nearby);
				params.put("phone", phone);
				params.put("week", week);
				params.put("datetime", datetime);
				params.put("name", name);
				params.put("lat", lat);
				params.put("lon", lon);

				files.put("uploadfile", sfile1);

				try {
					String resp = post(BASE_URL
							+ "?op=app_nearby&action=addshop", params, files,
							LoginHelper.getInstance().getBDUSS(), appContext);

					LogUtils.LOGD(TAG, "upload resp : " + resp);
					JSONObject jo = new JSONObject(resp);
					final Message message = new Message();
					if (jo != null) {
						message.errno = jo.optInt("errno", -1);
						message.msg = jo.optString("msg");

						if (message.errno == 0) {
							activity.runOnUiThread(new Runnable() {

								@Override
								public void run() {
									handler.onSuccess(message);
								}
							});

							return;
						}
					}
				} catch (IOException e) {
					e.printStackTrace();
				} catch (JSONException e) {
					e.printStackTrace();
				}

				activity.runOnUiThread(new Runnable() {

					@Override
					public void run() {
						handler.onFailure(null);
					}
				});

			}
		}).start();
	}

	public static void getShopTopAlbum(Context context,
			RYHttpResponseHandler handler, String shopid) {

		RequestParams params = getParams("app_photo", "shopphoto");
		params.put("shopid", shopid);
		params.put("pn", "0");
		params.put("rn", "65535");
		handler.setParser(new ShopTopAlbumParser());

		get(context, params, handler);
	}

	public static void getShopTypeAlbum(Context context,
			RYHttpResponseHandler handler, String shopid, String typeid) {

		RequestParams params = getParams("app_photo", "photolist");
		params.put("shopid", shopid);
		params.put("typeid", typeid);
		params.put("pn", "0");
		params.put("rn", "65535");
		handler.setParser(new ShopTypeAlbumParser());

		get(context, params, handler);
	}

	public static void getShopPhotoDetail(Context context,
			RYHttpResponseHandler handler, String shopid, String typeid,
			String photoid) {
		RequestParams params = getParams("app_photo", "photoinfo");
		params.put("shopid", shopid);
		params.put("typeid", typeid);
		params.put("photoid", photoid);
		handler.setParser(new ShopPhotoDetailParser());
		get(context, params, handler);
	}

	public static void getSigninList(Context context, int pn, int rn,
			RYHttpResponseHandler handler) {
		RequestParams params = getParams("app_nearby", "signinshoplist");
		params.put("cityid", Config.sCityId);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());
		}

		handler.setParser(new NearbyStoreParser());

		get(context, params, handler);
	}

	public static void getSearchSigninList(Context context, int pn, int rn,
			RYHttpResponseHandler handler, String shopName) {
		RequestParams params = getParams("app_nearby", "searchshopname");
		params.put("cityid", Config.sCityId);
		params.put("shopname", shopName);
		params.put("pn", pn + "");
		params.put("rn", rn + "");
		if (Config.sMyLocation != null) {
			params.put("lat", "" + Config.sMyLocation.getLatitude());
			params.put("lon", "" + Config.sMyLocation.getLongitude());
		}

		handler.setParser(new NearbyStoreParser());

		get(context, params, handler);
	}

	private static void get(Context context, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		Log.v(TAG, BASE_URL + " ====== " + params.toString());
		client.get(context, BASE_URL, params, responseHandler);
	}

	private static void post(Context context, String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		Log.v(TAG, url + " ====== " + params.toString());
		client.post(context, url, params, responseHandler);
	}

	private static void post(Context context, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		Log.v(TAG, BASE_URL + " ====== " + params.toString());
		client.post(context, BASE_URL, params, responseHandler);
	}

	private static RequestParams getParams(String op, String action) {
		RequestParams params = new RequestParams();
		if (!TextUtils.isEmpty(op)) {
			params.put("op", op);
		}
		if (!TextUtils.isEmpty(action)) {
			params.put("action", action);
		}

		return params;
	}

	/**
	 * 
	 * @param url
	 *            Service net address
	 * @param params
	 *            text content
	 * @param files
	 *            pictures
	 * @return String result of Service response
	 * @throws IOException
	 */
	private static String post(String url, Map<String, String> params,
			Map<String, File> files, String bduss, Context context)
			throws IOException {
		String BOUNDARY = java.util.UUID.randomUUID().toString();
		String PREFIX = "--", LINEND = "\r\n";
		String MULTIPART_FROM_DATA = "multipart/form-data";
		String CHARSET = "UTF-8";

		URL uri = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
		conn.setReadTimeout(10 * 1000);
		conn.setDoInput(true);
		conn.setDoOutput(true);
		conn.setUseCaches(false);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("connection", "keep-alive");
		conn.setRequestProperty("Charsert", "UTF-8");
		conn.setRequestProperty("Content-Type", MULTIPART_FROM_DATA
				+ ";boundary=" + BOUNDARY);
		conn.setRequestProperty("User-Agent",
				"android-async-http/1.4.1 (http://loopj.com/android-async-http)");
		conn.setRequestProperty("Cookie", "bduss=" + bduss);

		StringBuilder sb = new StringBuilder();
		for (Map.Entry<String, String> entry : params.entrySet()) {
			sb.append(PREFIX);
			sb.append(BOUNDARY);
			sb.append(LINEND);
			sb.append("Content-Disposition: form-data; name=\""
					+ entry.getKey() + "\"" + LINEND);
			sb.append("Content-Type: text/plain; charset=" + CHARSET + LINEND);
			sb.append("Content-Transfer-Encoding: 8bit" + LINEND);
			sb.append(LINEND);
			sb.append(entry.getValue());
			sb.append(LINEND);
		}

		DataOutputStream outStream = new DataOutputStream(
				conn.getOutputStream());
		outStream.write(sb.toString().getBytes());
		if (files != null) {
			String cacheDir = CompatibilityUtils.getDiskCacheDir(context);

			for (Map.Entry<String, File> file : files.entrySet()) {
				File uploadFile = null;

				if (cacheDir != null) {
					uploadFile = ImageUtils.compressBitmapFile(file.getValue(),
							cacheDir + File.separator
									+ file.getValue().getName(), 960, 60);
				}
				if (uploadFile == null) {
					uploadFile = file.getValue();
				}
				System.out.println("upload file : " + uploadFile);
				System.out.println("original file size : "
						+ file.getValue().length());
				System.out.println("upload file size : " + uploadFile.length());

				StringBuilder sb1 = new StringBuilder();
				sb1.append(PREFIX);
				sb1.append(BOUNDARY);
				sb1.append(LINEND);
				sb1.append("Content-Disposition: form-data; name=\""
						+ file.getKey() + "\"; filename=\""
						+ uploadFile.getName() + "\"" + LINEND);
				sb1.append("Content-Type: application/octet-stream; charset="
						+ CHARSET + LINEND);
				sb1.append(LINEND);
				outStream.write(sb1.toString().getBytes());

				InputStream is = new FileInputStream(uploadFile);
				byte[] buffer = new byte[1024];
				int len = 0;
				while ((len = is.read(buffer)) != -1) {
					outStream.write(buffer, 0, len);
				}

				is.close();
				outStream.write(LINEND.getBytes());
			}
		}

		byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
		outStream.write(end_data);
		outStream.flush();
		int res = conn.getResponseCode();
		InputStream in = conn.getInputStream();
		StringBuilder sb2 = new StringBuilder();
		if (res == 200) {
			int ch;
			while ((ch = in.read()) != -1) {
				sb2.append((char) ch);
			}
		}
		outStream.close();
		conn.disconnect();
		return sb2.toString();
	}
}
